package com.itshare.video.controller;

import com.github.pagehelper.PageHelper;
import com.itshare.video.common.annontation.AttrData;
import com.itshare.video.common.annontation.Page;
import com.itshare.video.common.annontation.Size;
import com.itshare.video.common.aop.xss.annontation.CleanXSS;
import com.itshare.video.common.core.constant.enums.ApiInfo;
import com.itshare.video.common.dto.PageEntity;
import com.itshare.video.common.dto.QueryInfo;
import com.itshare.video.common.dto.Result;
import com.itshare.video.pojo.bo.FeedBackMessageBO;
import com.itshare.video.pojo.bo.ReportVideoMessageBO;
import com.itshare.video.pojo.code.MessageType;
import com.itshare.video.pojo.dto.ReplyMsgDTO;
import com.itshare.video.pojo.dto.UserTokenDTO;
import com.itshare.video.service.UserMessageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author lyr
 * @create 2020/10/31 14:28
 */
@Validated
@RestController
@RequestMapping("/api/")
public class EventMessageController {


    @Resource
    private UserMessageService userMessageService;

    /**
     * 获取自己的消息
     *
     * @param
     * @return
     */
    @GetMapping("/message")
    public Result<?> userMessageGetByUserId(@AttrData UserTokenDTO userTokenDTO,
                                            @RequestParam(required = false) Integer msgType) {

        return Result.of(ApiInfo.OK)
                .setData(userMessageService.getUserMessage(userTokenDTO.getId(), msgType));
    }

    /**
     * 需要有管理员权限，获取审核信息
     *
     * @param userTokenDTO
     * @return
     */
    @RequiresPermissions("manager:video:all")
    @GetMapping("/feedback_msg")
    public Result<?> getfeedbackMsg(@AttrData UserTokenDTO userTokenDTO,
                                    @Page Integer page, @Size Integer size) {
        PageHelper.startPage(page, size);


        // 获取 用户  的反馈信息列表
        return Result.of(ApiInfo.OK)
                .setData(
                        userMessageService.getFeedBackMessage(userTokenDTO)
                );
    }


    /**
     * 用户举报发送举报消息接口 给管理员
     * {
     * 举报带上视频ID ，和 举报的内容描述
     * }
     *
     * @return
     */
    @CleanXSS
    @PostMapping("/report_video_msg")
    public Result<?> reportMessage(@AttrData UserTokenDTO userTokenDTO, @Validated @RequestBody ReportVideoMessageBO reportVideoMessageBO) {
        //用户举报视频
        return userMessageService
                .reportVideoIllegal(reportVideoMessageBO, userTokenDTO);


    }

    //TODO: 用户反馈

    /**
     * 用户反馈 内容
     *
     * @return
     */
    @CleanXSS
    @PostMapping("/feedback_msg")
    public Result<?> userFeedBackMessage(@RequestBody @Validated FeedBackMessageBO feedBackMessageBO,
                                         @AttrData UserTokenDTO userTokenDTO) {
        //用户反馈视频内容
        return userMessageService.userFeedback(feedBackMessageBO, userTokenDTO);
        // System.out.println(feedBackMessageBO);
        // return Result.success();
    }

    //----------------------------------------------------

    @RequiresPermissions("manager:video:all")
    @DeleteMapping("/usermsg/{msgId}")
    public Result<?> deleteUsermsg(@PathVariable Integer msgId) {
        // return userMessageService.handleFt
        //todo: xx
        userMessageService.deleteMsg(msgId);
        return Result.success();
    }


    @CleanXSS
    @PostMapping("/usermsg_reply")
    public Result<?> replyMsg(
            @AttrData UserTokenDTO userTokenDTO,
            @RequestParam Integer msgId,
            @RequestBody ReplyMsgDTO replyMsgDTO) {
        userMessageService.replyMsg(msgId, replyMsgDTO, userTokenDTO);
        return Result.success();
    }


    @RequiresPermissions("manager:video:all")
    @GetMapping("/usermsg_feedback")
    public Result feedbackmsg(@Page Integer page,
                              @Size Integer size) {
        PageEntity  entity = userMessageService
                .getFeedbackMsg(MessageType.FEEDBACK_MSG.type, QueryInfo.ofNullable(page,size,null));
        return Result.of(ApiInfo.OK)
                .setData(entity);
    }


}
